//
//  TZDetailViewController.m
//  iOS-CtrlV
//
//  Created by Wang Li on 12-12-24.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "TZDetailViewController.h"
#import "ASIHTTPRequest.h"
#import "CJSONDeserializer.h"
#import "AsyncImageView.h"
#import <QuartzCore/QuartzCore.h>
#import "asyncimageview.h"
#import "MainTabBarController.h"
#import "LoginViewController.h"
#import "SettingViewController.h"
#import "AddAlbumViewController.h"
#import "SCGIFImageView.h"
#import <MediaPlayer/MediaPlayer.h>
#import "ASIFormDataRequest.h"
#import "CollectListViewController.h"
#import "OwnViewController.h"
#import "TZScrollViewController.h"
//#define Top_PageH 200
#define Mid_BttH 50
#define User_Info 40
#define CollectH 190 //专辑横向总高
#define CollectRealH 180 //专辑横向总高
#define UserCellH 42 //人儿一行高
#define LikeH 40 //喜欢的高
@interface TZDetailViewController ()

@end

@implementation TZDetailViewController
@synthesize m_DetailID;
@synthesize m_NeedFirstDataRequest;
@synthesize m_MainTabBar;
@synthesize m_ViewController;
- (id)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        m_NeedFirstDataRequest=NO;
        
        _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44)];
        [_ContentScrollView setBackgroundColor:[UIColor whiteColor]];
        _PageImgShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
        
        [self addSubview:_ContentScrollView];
    
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDiss:) name:UIKeyboardWillHideNotification object:nil];
        
//        UISwipeGestureRecognizer* tPanGesture =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(changePageData:)];
//        tPanGesture.numberOfTouchesRequired =1;
//        tPanGesture.direction = UISwipeGestureRecognizerDirectionRight;
//        [self addGestureRecognizer:tPanGesture];
//        [tPanGesture release];
//        
//        UISwipeGestureRecognizer* tLeftPanGesture =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(changePageData:)];
//        tLeftPanGesture.numberOfTouchesRequired =1;
//        tLeftPanGesture.direction = UISwipeGestureRecognizerDirectionLeft;
//        [self addGestureRecognizer:tLeftPanGesture];
//        [tLeftPanGesture release];
    }
    return self;
}

-(void) dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self hudWasHidden:nil];
    [_SharePick release];
    [_CommentField release];
    [_PageImgShadow removeFromSuperview];
    [_PageImgShadow release];
    [_pageShowNumLab removeFromSuperview];
    [_pageShowNumLab release];
    [_ContentScrollView release];
    [_DettailDataDic release];
    [m_DetailID release];
    [super dealloc];
}



-(void) requestDetail
{
    [self addHudLoad];
    [_ContentScrollView removeFromSuperview];
    [_ContentScrollView release];
    _ContentScrollView= nil;
    _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44)];
    [_ContentScrollView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:_ContentScrollView];
    if ([m_DetailID length] == 0) {
        self.m_DetailID =@"23862";
    }
    NSURL* tRequestURL =nil;
    if (m_MainTabBar.m_UserDic != nil) {
        tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@?app=blog&act=detail&id=%@&user_id=%@",RequestMainURL,m_DetailID,[m_MainTabBar.m_UserDic objectForKey:@"user_id"]]];
    }else{
        tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@?app=blog&act=detail&id=%@",RequestMainURL,m_DetailID]];
    }
    ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
    [tRequestSearchNum setDelegate:self];
    [tRequestSearchNum setDidFinishSelector:@selector(requestTZDetailFinish:)];
    [tRequestSearchNum startAsynchronous];
}


//-(void)changePageData:(UISwipeGestureRecognizer*)swipe
//{
//    NSString* tURLStr = nil;
//    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
//    
//    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
//        int tLeftID =[[_DettailDataDic objectForKey:@"next_id"] intValue];
//        if (tLeftID <= 0) {
//            [tAppDel showWithCustomView:@"提示" detailText:@"没有下一页了" isCue:NO delayTime:3.0f];
//            return;
//        }
//        self.m_DetailID =[NSString stringWithFormat:@"%d",tLeftID];
//        tURLStr=[NSString stringWithFormat:@"%@?app=blog&act=detail&id=%@",RequestMainURL,[_DettailDataDic objectForKey:@"next_id"]];
//    }else if(swipe.direction == UISwipeGestureRecognizerDirectionRight){
//        int tRightID =[[_DettailDataDic objectForKey:@"pre_id"] intValue];
//        if (tRightID <= 0) {
//            [tAppDel showWithCustomView:@"提示" detailText:@"没有上一页了" isCue:NO delayTime:3.0f];
//            return;
//        }
//        self.m_DetailID =[NSString stringWithFormat:@"%d",tRightID];
//        tURLStr=[NSString stringWithFormat:@"%@?app=blog&act=detail&id=%@",RequestMainURL,[_DettailDataDic objectForKey:@"pre_id"]];
//    }
//    [_ContentScrollView removeFromSuperview];
//    [_ContentScrollView release];
//    _ContentScrollView= nil;
//    _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44)];
//    [_ContentScrollView setBackgroundColor:[UIColor whiteColor]];
//    [self addSubview:_ContentScrollView];
//    NSURL* tRequestURL =[NSURL URLWithString:tURLStr];
//    ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
//    [tRequestSearchNum setDelegate:self];
//    [tRequestSearchNum setDidFinishSelector:@selector(requestTZDetailFinish:)];
//    [tRequestSearchNum startAsynchronous];
//}

//-(void) navBackBtt
//{
//    [_BackBttBarItem removeFromSuperview];
//    [self.navigationController popViewControllerAnimated:YES];
//}


- (void)requestTZDetailFinish:(ASIHTTPRequest *)request;
{
    NSError* tError;
    
    NSString* tReqStr = /*@"{\"errorCode\":0,\"errorMsg\":"",\"data\":{\"id\":229497,\"image\":[{\"url\":\"http:\/\/img01.lvguo.com\/2012\/10\/15\/6_0d252de4df.jpg\"},{\"url\":\"http:\/\/img01.lvguo.com\/2012\/10\/15\/6_0d252de4df.jpg\"}],\"description\":\"6.3\u5143\u5403\u4e00\u5929\uff0c\u4f60\u6562\u4e0d\u6562\uff0110\u670817\u65e5\u662f\u56fd\u9645\u6d88\u9664\u8d2b\u56f0\u65e5\u3002\u6309\u7167\u4eba\u5747\u5e74\u6536\u51652300\u5143\u7684\u6807\u51c6\uff0c\u8d2b\u56f0\u5c31\u662f\u90a3\u4e9b\u6bcf\u5929\u6536\u5165\u4e0d\u8db36.3\u5143\u7684\u4eba\u30026.3\u5143\u5bf9\u4e8e\u4f60\u4e5f\u8bb8\u53ea\u662f\u4e00\u987f\u65e9\u9910\uff0c\u4f46\u5bf9\u4e8e\u8d2b\u56f0\u4eba\u7fa4\u6765\u8bf4\uff0c\u662f\u4e00\u6574\u5929\u8f9b\u52e4\u52b3\u4f5c\u7684\u6536\u5165\u3002\u5b54\u96c0V\u63d0\u5021\u5927\u5bb6\u4eb2\u81ea\u4f53\u9a8c6.3\u5143\u5403\u4e00\u5929\uff0c\u8ba9\u4f53\u9a8c\u89e6\u52a8\u5173\u7231\uff01\u5feb\u6765\u6652\u6652\u4f60\u768463\u8ba1\u5212\u5427\uff01\",\"forward\":0,\"favorite\":0,\"user_id\":212,\"user_nickname\":\"lemon\u67e0\",\"user_avatar\":\"http:\/\/img03.lvguo.com\/user\/212\/7_25149cc314.jpg\",\"collect_name\":\"\u597d\u65e0\u804a\",\"location\":\"\",\"lccation_id\":\"759731\",\"created\":\"2012-10\"}}";//*/[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    [_DettailDataDic release];
    _DettailDataDic =nil;
    _DettailDataDic = [tDictionary objectForKey:@"data"];
    [_DettailDataDic retain];
    NSString* tAllPosStr = [_DettailDataDic objectForKey:@"position"];
    NSArray* tNumArr = [tAllPosStr componentsSeparatedByString:@"/"];
    if ([m_ViewController respondsToSelector:@selector(tellSupperCurrent:TotallNum:)]) {
        int tCurrentPage = [[tNumArr objectAtIndex:0] intValue];
        int tCurrentAllPage = [[tNumArr objectAtIndex:1] intValue];
        [m_ViewController tellSupperCurrent:tCurrentPage TotallNum:tCurrentAllPage];
    }
    
    int tIndex =0;
    
    int tTypeImg= [[_DettailDataDic objectForKey:@"image_type"] intValue];
    UIView* tAsyImg =nil;
    int tTopImgWidth =[[_DettailDataDic objectForKey:@"image_width"] intValue];
    int tTopImgHeight =[[_DettailDataDic objectForKey:@"image_height"] intValue];
    float tScaleImg =320.f/tTopImgWidth;
    tTopImgHeight = tTopImgHeight*tScaleImg;
    NSString* tImgStr = [_DettailDataDic objectForKey:@"image"];
    if (tTypeImg == 1) {
        if ([[tImgStr substringWithRange:NSMakeRange([tImgStr length]-3, 3)] isEqualToString:@"gif"]) {
            tAsyImg = [[SCGIFImageView alloc] initWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:tImgStr]] speed:120];
            tAsyImg.frame =CGRectMake(0, 0, 320, tTopImgHeight);
            tAsyImg.tag =0x300;
            [_ContentScrollView addSubview:tAsyImg];
            [tAsyImg release];
        }else{
            tAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 320, tTopImgHeight)];
            tAsyImg.tag =0x300;
            ((AsyncImageView*)tAsyImg)._imageRequestURL = [_DettailDataDic objectForKey:@"image"];
            ((AsyncImageView*)tAsyImg)._numStateRequested =need_Request;
            ((AsyncImageView*)tAsyImg).m_BoolSetImage =YES;
            ((AsyncImageView*)tAsyImg).userInteractionEnabled =NO;
            [_ContentScrollView addSubview:tAsyImg];
            [((AsyncImageView*)tAsyImg) customLoadImageFromURL];
            [((AsyncImageView*)tAsyImg) release];
        }
    }else{
        tAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 320, tTopImgHeight)];
        tAsyImg.tag =0x300;
        ((AsyncImageView*)tAsyImg)._imageRequestURL = [_DettailDataDic objectForKey:@"image"];
        ((AsyncImageView*)tAsyImg)._numStateRequested =need_Request;
        ((AsyncImageView*)tAsyImg).m_BoolSetImage =YES;
        ((AsyncImageView*)tAsyImg).userInteractionEnabled =NO;
        [_ContentScrollView addSubview:tAsyImg];
        [((AsyncImageView*)tAsyImg) customLoadImageFromURL];
        [((AsyncImageView*)tAsyImg) release];
    }
    _PageImgShadow.frame =CGRectMake(0, tTopImgHeight, 320, 5);
    //右上角数量
    NSString* tPosStr = [_DettailDataDic objectForKey:@"position"];
    UIFont* tNumFont =[UIFont systemFontOfSize:14];
    CGSize tNumSize = [tPosStr sizeWithFont:tNumFont];
    tNumSize.width +=16;
    UILabel* tNumLab =[[UILabel alloc] initWithFrame:CGRectMake(320-tNumSize.width, 0, tNumSize.width, 20)];
    [tNumLab setFont:tNumFont];
    [tNumLab setTextColor:[UIColor whiteColor]];
    if ([tPosStr length] > 0) {
        [tNumLab setText:tPosStr];
    }
    tNumLab.textAlignment =UITextAlignmentCenter;
    [tNumLab setBackgroundColor:[UIColor colorWithRed:93/255.f green:93/255.f blue:93/255.f alpha:1]];
    [_ContentScrollView addSubview:tNumLab];
    [tNumLab release];

    //按钮
    UIButton* tTopBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tTopBtt.frame =tAsyImg.frame;
    tTopBtt.tag =tIndex;
    [tTopBtt addTarget:self action:@selector(topImagePressed:) forControlEvents:UIControlEventTouchUpInside];
    [_ContentScrollView addSubview:tTopBtt];
    
    
    
    //转采 和 喜欢部分
    UIView*  tMidView = [[UIView alloc] initWithFrame:CGRectMake(0, tTopImgHeight, 320, Mid_BttH)];
    [tMidView setBackgroundColor:[UIColor colorWithRed:236/255.f  green:238/255.f  blue:235/255.f alpha:1]];
    [_ContentScrollView addSubview:tMidView];
    [_ContentScrollView addSubview:_PageImgShadow];
    UIButton* tZCBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [tZCBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];
    tZCBtt.frame =CGRectMake(8, 8, 70, 34);
    [tZCBtt setTitle:@"转采" forState:UIControlStateNormal];
    [tZCBtt setTitleColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1] forState:UIControlStateNormal];
    [tZCBtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [tZCBtt addTarget:self action:@selector(ZCBttPressed) forControlEvents:UIControlEventTouchUpInside];
    [tMidView addSubview:tZCBtt];
    
    int tIsLike =[[_DettailDataDic objectForKey:@"liked"] intValue];
    UIButton* tLikeBtt =[UIButton buttonWithType:UIButtonTypeCustom];
    [tLikeBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];
    tLikeBtt.frame =CGRectMake(90, 8, 70, 34);
    tLikeBtt.layer.cornerRadius =5.f;
    //[tLikeBtt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tLikeBtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    if (tIsLike == 0) {
        [tLikeBtt setTitle:@"喜欢" forState:UIControlStateNormal];
    }else{
        [tLikeBtt setTitle:@"取消喜欢" forState:UIControlStateNormal];
    }
    [tLikeBtt setTitleColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1] forState:UIControlStateNormal];
    [tLikeBtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [tLikeBtt addTarget:self action:@selector(dolikeRequest:) forControlEvents:UIControlEventTouchUpInside];
    [tMidView addSubview:tLikeBtt];
    
    UIButton* tNextBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [tNextBtt addTarget:self action:@selector(shareWeiBo) forControlEvents:UIControlEventTouchUpInside];
    [tNextBtt setBackgroundImage:[UIImage imageNamed:@"next_button.png"] forState:UIControlStateNormal];
    tNextBtt.frame =CGRectMake(258, 8, 52, 34);
    [tMidView addSubview:tNextBtt];
    [tMidView release];
    
    //说明部分
    int tDesTextH = 10;
    UITextView* tDesTextView=[[UITextView alloc] initWithFrame:CGRectMake(6, 0, 308, 10)];
    tDesTextView.editable =NO;
    [tDesTextView setFont:[UIFont systemFontOfSize:12]];
    [_ContentScrollView addSubview:tDesTextView];
    [tDesTextView setBackgroundColor:[UIColor clearColor]];
    tDesTextView.text = [_DettailDataDic objectForKey:@"description"];
    
    [tDesTextView setTextColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1]];
    tDesTextH = tDesTextView.contentSize.height;
    tDesTextView.frame =CGRectMake(6, Mid_BttH+tTopImgHeight, 308, tDesTextH);
    tDesTextView.scrollEnabled =NO;
    [tDesTextView release];
    tDesTextH += 10;
    //线
    UIImageView* tLineImgView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment_line.png"]];
    tLineImgView.frame =CGRectMake(0, Mid_BttH+tTopImgHeight+tDesTextH, 320, 6);
    [_ContentScrollView addSubview:tLineImgView];
    [tLineImgView release];
    tDesTextH+=(12);
    
    AsyncImageView* tUserHeadAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(10, Mid_BttH+tTopImgHeight+tDesTextH, 25, 25)];
    tUserHeadAsyImg._imageRequestURL = [_DettailDataDic objectForKey:@"user_avatar"];
    tUserHeadAsyImg._numStateRequested =need_Request;
    tUserHeadAsyImg.m_BoolSetImage =YES;
    tUserHeadAsyImg.userInteractionEnabled =NO;
    [_ContentScrollView addSubview:tUserHeadAsyImg];
    [tUserHeadAsyImg customLoadImageFromURL];
    [tUserHeadAsyImg release];
    UIButton* tHeaderBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tHeaderBtt.frame = tUserHeadAsyImg.frame;
    [tHeaderBtt addTarget: self action:@selector(pressedHeader) forControlEvents:UIControlEventTouchUpInside];
    [_ContentScrollView addSubview:tHeaderBtt];
    
    
    int tTempValue =0;
    NSString* tUserName = [_DettailDataDic objectForKey:@"user_nickname"];
    NSString* tCollectName = [_DettailDataDic objectForKey:@"collect_name"];
    NSString* tMidWord =@"分享到";
    UIFont* tFont =[UIFont systemFontOfSize:11];
    CGSize tSize =[tUserName sizeWithFont:tFont];
    UILabel* tUserNameLab =[[UILabel alloc] initWithFrame:CGRectMake(50, Mid_BttH+tTopImgHeight+tDesTextH-3, tSize.width+4, 18)];
    [tUserNameLab setBackgroundColor:[UIColor clearColor]];
    [tUserNameLab setFont:tFont];
    [tUserNameLab setText:tUserName];
    [_ContentScrollView addSubview:tUserNameLab];
    [tUserNameLab release];
    
    UIButton* tNameBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tNameBtt.frame = tUserNameLab.frame;
    [tNameBtt addTarget: self action:@selector(pressedHeader) forControlEvents:UIControlEventTouchUpInside];
    [_ContentScrollView addSubview:tNameBtt];
    
    tTempValue +=tSize.width+4;
    tSize =[tMidWord sizeWithFont:tFont];
    UILabel* tMidLab =[[UILabel alloc] initWithFrame:CGRectMake(50+tTempValue, Mid_BttH+tTopImgHeight+tDesTextH-3, tSize.width+4, 18)];
    [tMidLab setBackgroundColor:[UIColor clearColor]];
    [tMidLab setFont:tFont];
    [tMidLab setText:tMidWord];
    [tMidLab setTextColor:[UIColor grayColor]];
    [_ContentScrollView addSubview:tMidLab];
    [tMidLab release];
    
    tTempValue +=tSize.width+4;
    tSize =[tCollectName sizeWithFont:tFont];
    UILabel* tCollectLab =[[UILabel alloc] initWithFrame:CGRectMake(50+tTempValue, Mid_BttH+tTopImgHeight+tDesTextH-3, tSize.width+4, 18)];
    [tCollectLab setBackgroundColor:[UIColor clearColor]];
    [tCollectLab setFont:tFont];
    [tCollectLab setText:tCollectName];
    [_ContentScrollView addSubview:tCollectLab];
    [tCollectLab release];
    UIButton* tCollectBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tCollectBtt.frame = tCollectLab.frame;
    [tCollectBtt addTarget: self action:@selector(pressedShowCollect) forControlEvents:UIControlEventTouchUpInside];
    [_ContentScrollView addSubview:tCollectBtt];
    
    UILabel* tTimeLab =[[UILabel alloc] initWithFrame:CGRectMake(50, Mid_BttH+tTopImgHeight+tDesTextH+13, 240, 18)];
    [tTimeLab setBackgroundColor:[UIColor clearColor]];
    [tTimeLab setFont:tFont];
    [tTimeLab setText:[_DettailDataDic objectForKey:@"created"]];
    [tTimeLab setTextColor:[UIColor grayColor]];
    [_ContentScrollView addSubview:tTimeLab];
    [tTimeLab release];
    
    
    //地点
    int tShowH =Mid_BttH+tTopImgHeight+tDesTextH+User_Info;
    if ([[_DettailDataDic objectForKey:@"lccation"] length] > 0) {
        UIImageView* tLocationImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, Mid_BttH+tTopImgHeight+tDesTextH+User_Info, 25, 25)];
        [tLocationImg setImage:[UIImage imageNamed:@"location.png"]];
        [_ContentScrollView addSubview:tLocationImg];
        [tLocationImg release];
        
        UILabel* tLocationLab =[[UILabel alloc] initWithFrame:CGRectMake(56, Mid_BttH+tTopImgHeight+tDesTextH+User_Info+6, 240, 18)];
        [tLocationLab setBackgroundColor:[UIColor clearColor]];
        [tLocationLab setFont:[UIFont boldSystemFontOfSize:16]];
        [tLocationLab setText:[_DettailDataDic objectForKey:@"lccation"]];
        [_ContentScrollView addSubview:tLocationLab];
        [tLocationLab release];
        
        tShowH+= User_Info;
    }

    NSArray* tComArr = [_DettailDataDic objectForKey:@"comments"];
    int tCommIndex = 0;
    for (NSDictionary* tComDic in tComArr) {
        UIView* tTalkView =[[UIView alloc] initWithFrame:CGRectMake(0, tShowH, 320, 48)];
        [tTalkView setBackgroundColor:[UIColor colorWithRed:236/255.f green:238/255.f blue:235/255.f alpha:1]];
        [_ContentScrollView addSubview:tTalkView];
        [tTalkView release];
        
        AsyncImageView* tUserHeadAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(10, tShowH+9, 25, 25)];
        tUserHeadAsyImg._imageRequestURL = [tComDic objectForKey:@"user_avatar"];
        tUserHeadAsyImg._numStateRequested =need_Request;
        tUserHeadAsyImg.m_BoolSetImage =YES;
        tUserHeadAsyImg.userInteractionEnabled =NO;
        [_ContentScrollView addSubview:tUserHeadAsyImg];
        [tUserHeadAsyImg customLoadImageFromURL];
        [tUserHeadAsyImg release];
        
        UIButton* tCommHeadBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        //tCommHeadBtt.frame = tUserHeadAsyImg.frame;
        tCommHeadBtt.frame = CGRectMake(10,tShowH+9,230,30);
        tCommHeadBtt.tag =tCommIndex;
        [tCommHeadBtt addTarget: self action:@selector(pressedCommHead:) forControlEvents:UIControlEventTouchUpInside];
        [_ContentScrollView addSubview:tCommHeadBtt];
        
        UILabel* tUserNameLab =[[UILabel alloc] initWithFrame:CGRectMake(50, tShowH+5, 250, 18)];
        [tUserNameLab setBackgroundColor:[UIColor clearColor]];
        [tUserNameLab setFont:tFont];
        [tUserNameLab setText:[tComDic objectForKey:@"user_nickname"]];
        [_ContentScrollView addSubview:tUserNameLab];
        [tUserNameLab release];
        
        UILabel* tContentLab =[[UILabel alloc] initWithFrame:CGRectMake(50, tShowH+20, 250, 18)];
        [tContentLab setBackgroundColor:[UIColor clearColor]];
        [tContentLab setFont:tFont];
        [tContentLab setTextColor:[UIColor grayColor]];
        [tContentLab setText:[tComDic objectForKey:@"content"]];
        [_ContentScrollView addSubview:tContentLab];
        [tContentLab release];
        
        tShowH+=40;
        tCommIndex++;
    }
    
    //评论
    UIView* tTalkView =[[UIView alloc] initWithFrame:CGRectMake(0, tShowH, 320, 38)];
    [tTalkView setBackgroundColor:[UIColor colorWithRed:236/255.f green:238/255.f blue:235/255.f alpha:1]];
    [_ContentScrollView addSubview:tTalkView];
    [tTalkView release];
    UIImageView* tCommentImg =[[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 22, 22)];
    [tCommentImg setImage:[UIImage imageNamed:@"comment.png"]];
    [tTalkView addSubview:tCommentImg];
    [tCommentImg release];
    CALayer* tRectLayer =[CALayer layer];
    tRectLayer.frame =CGRectMake(40, 8, 270, 22);
    tRectLayer.borderWidth =1;
    tRectLayer.borderColor = [UIColor colorWithRed:180/255.f green:180/255.f blue:180/255.f alpha:1].CGColor;
    [tTalkView.layer addSublayer:tRectLayer];
    _CommentField = [[UITextField alloc] initWithFrame:CGRectMake(43, 10, 264, 18)];
    [_CommentField setBackgroundColor:[UIColor whiteColor]];
    _CommentField.delegate =self;
    _CommentField.returnKeyType =UIReturnKeySend;
    [_CommentField setFont:[UIFont systemFontOfSize:12]];
    _CommentField.placeholder=@"评论";
    [tTalkView addSubview:_CommentField];
    tShowH+=38;
    _ShowFieldH = tShowH;
    
    //转发专辑
    NSArray* tForwardsArr =[_DettailDataDic objectForKey:@"forwards"];
    int tBttTag = 0;
    if ([tForwardsArr count] > 0) {
        int tForCount =[[_DettailDataDic objectForKey:@"forward"] intValue];
        UILabel* tZFLab =[[UILabel alloc] initWithFrame:CGRectMake(10, tShowH+10, 310, 18)];
        [tZFLab setBackgroundColor:[UIColor clearColor]];
        [tZFLab setFont:[UIFont boldSystemFontOfSize:14]];
        [tZFLab setText:[NSString stringWithFormat:@"%d  转发",tForCount]];
        [_ContentScrollView addSubview:tZFLab];
        [tZFLab release];
        tShowH+=40;
        UIScrollView* tCollectScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, tShowH, 320, CollectH)];
        tCollectScroll.showsHorizontalScrollIndicator =NO;
        tCollectScroll.showsVerticalScrollIndicator =NO;
        [tCollectScroll setBackgroundColor:[UIColor colorWithRed:193/255.f green:193/255.f blue:193/255.f alpha:1]];
        [_ContentScrollView addSubview:tCollectScroll];
        [tCollectScroll release];
        ////
        tCollectScroll.contentSize =CGSizeMake(155*[tForwardsArr count], CollectH);
        
        for (NSDictionary* tCollectDic in tForwardsArr) {
            if (tBttTag >= tForCount) {
                break;
            }
            UIImage* tLineImg =[UIImage imageNamed:@"collect_footer.png"];
            UIFont* tTitleFont =[UIFont systemFontOfSize:11];
            UIButton* tCustomBtt = [UIButton buttonWithType:UIButtonTypeCustom];
            tCustomBtt.tag = tBttTag;
            [tCustomBtt addTarget:self action:@selector(bttToShowPBL:) forControlEvents:UIControlEventTouchUpInside];
            tCustomBtt.frame =CGRectMake(155*tBttTag, 5, 145, CollectRealH);
            [tCustomBtt setBackgroundColor:[UIColor whiteColor]];
            CALayer* tLineLayer = [CALayer layer];
            tLineLayer.frame =CGRectMake(0, CollectRealH-5, 145, 5);
            tLineLayer.contents =(id)tLineImg.CGImage;
            [tCustomBtt.layer addSublayer:tLineLayer];
            [tCollectScroll addSubview:tCustomBtt];
            NSArray* tCollectImgs= [tCollectDic objectForKey:@"image"];
            int tImgIndex = 0;
            for (NSString* tImgDic in tCollectImgs) {
                AsyncImageView* tAsyImg =[[AsyncImageView alloc] initWithFrame:CGRectMake(155*tBttTag+2+tImgIndex%2*70, 5+2+tImgIndex/2*70, 70, 70)];
                
                [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];
                
                NSString* tImgURL =tImgDic;
                tAsyImg._imageRequestURL =tImgURL;
                tAsyImg._numStateRequested =need_Request;
                tAsyImg.m_BoolSetImage =YES;
                tAsyImg.userInteractionEnabled =NO;
                
                [tCollectScroll addSubview:tAsyImg];
                [tAsyImg customLoadImageFromURL];
                [tAsyImg release];
                tImgIndex++;
            }
            
            CGSize tTitleSize =[[tCollectDic objectForKey:@"title"] sizeWithFont:tTitleFont];
            UILabel* tTitelLab =[[UILabel alloc] initWithFrame:CGRectMake(4, 150, tTitleSize.width+2, 20)];
            [tTitelLab setBackgroundColor:[UIColor clearColor]];
            [tTitelLab setText:[tCollectDic objectForKey:@"title"]];
            [tTitelLab setTextColor:[UIColor blackColor]];
            [tTitelLab setFont:tTitleFont];
            [tCustomBtt addSubview:tTitelLab];
            [tTitelLab release];
            
            UILabel* tNumLab =[[UILabel alloc] initWithFrame:CGRectMake(4+tTitleSize.width+6, 150,70, 20)];
            [tNumLab setBackgroundColor:[UIColor clearColor]];
            [tNumLab setText:[tCollectDic objectForKey:@"count"]];
            [tNumLab setTextColor:[UIColor grayColor]];
            [tNumLab setFont:tTitleFont];
            [tCustomBtt addSubview:tNumLab];
            [tNumLab release];
            
            tBttTag++;
        }

        ///
        UIImageView* tLineImgView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
        tLineImgView.frame =CGRectMake(0, tShowH, 320, 5);
        [_ContentScrollView addSubview:tLineImgView];
        [tLineImgView release];
        
        tShowH+=CollectH;
           }
        //喜欢部分
        NSArray* tLikesArr =[_DettailDataDic objectForKey:@"likes"];
        if ([tLikesArr count] > 0) {
            UILabel* tZFLab =[[UILabel alloc] initWithFrame:CGRectMake(10, tShowH+10, 310, 18)];
            [tZFLab setBackgroundColor:[UIColor clearColor]];
            [tZFLab setFont:[UIFont boldSystemFontOfSize:14]];
            [tZFLab setText:[NSString stringWithFormat:@"%d  喜欢",[tLikesArr count]]];
            [_ContentScrollView addSubview:tZFLab];
            [tZFLab release];
            tShowH+=LikeH;
            tBttTag =0;
            for(NSDictionary* tUserDic in tLikesArr){
                CALayer* tLineLayer =[CALayer layer];
                tLineLayer.frame = CGRectMake(0, tShowH+UserCellH-1, 320, 1);
                [tLineLayer setBackgroundColor:[UIColor colorWithRed:178/255.f green:178/255.f blue:178/255.f alpha:1].CGColor];
                [_ContentScrollView.layer addSublayer:tLineLayer];
                
                AsyncImageView* tAsyImg =[[AsyncImageView alloc] initWithFrame:CGRectMake(4, tShowH+4, 34, 34)];
                
                [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];

                
                NSString* tImgURL =[tUserDic objectForKey:@"user_avatar"];
                tAsyImg._imageRequestURL =tImgURL;
                tAsyImg._numStateRequested =need_Request;
                tAsyImg.m_BoolSetImage =YES;
                tAsyImg.userInteractionEnabled =NO;
                [_ContentScrollView addSubview:tAsyImg];
                [tAsyImg customLoadImageFromURL];
                [tAsyImg release];
                
                
                UIButton* tLikeHeadBtt = [UIButton buttonWithType:UIButtonTypeCustom];
                tLikeHeadBtt.frame = CGRectMake(4, tShowH+4, 230, 34);
                tLikeHeadBtt.tag =tBttTag;
                [tLikeHeadBtt addTarget: self action:@selector(pressedLikeHead:) forControlEvents:UIControlEventTouchUpInside];
                [_ContentScrollView addSubview:tLikeHeadBtt];
                
                
                UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(50, tShowH+12, 200, 16)];
                [tNameLab setBackgroundColor:[UIColor clearColor]];
                [tNameLab setText:[tUserDic objectForKey:@"user_nickname"]];
                [tNameLab setFont:[UIFont systemFontOfSize:15]];
                [_ContentScrollView addSubview:tNameLab];
                [tNameLab release];
                
                NSString* tShowID = [tUserDic objectForKey:@"user_id"];
                NSString* tSelfID = [m_MainTabBar.m_UserDic objectForKey:@"user_id"];
                BOOL tNeedBtt =YES;
                if ([tSelfID length] > 0&& [tSelfID isEqualToString:tShowID]) {
                    tNeedBtt =NO;
                }
                if (tNeedBtt) {
                    UIButton* tBttFollow=[UIButton buttonWithType:UIButtonTypeCustom];
                    tBttFollow.layer.cornerRadius =4.f;
                    tBttFollow.layer.borderWidth =1;
                    tBttFollow.layer.borderColor =[UIColor grayColor].CGColor;
                    tBttFollow.frame =CGRectMake(320-63, tShowH+7, 53, 28);
                    tBttFollow.layer.borderColor = [UIColor colorWithRed:192/255.f green:192/255.f blue:192/255.f alpha:1].CGColor;
                    if ([[tUserDic objectForKey:@"isfollowed"] intValue] == 0) {
                        [tBttFollow setTitle:@"关注" forState:UIControlStateNormal];
                    }else{
                        [tBttFollow setTitle:@"取消关注" forState:UIControlStateNormal];
                    }
                    [tBttFollow.titleLabel setFont:[UIFont systemFontOfSize:12]];
                    [tBttFollow setTitleColor:[UIColor colorWithRed:100/255.f green:100/255.f  blue:100/255.f  alpha:1] forState:UIControlStateNormal];
                    [tBttFollow addTarget:self action:@selector(guanZhuBtt:) forControlEvents:UIControlEventTouchUpInside];
                    tBttFollow.tag =tBttTag;
                    [_ContentScrollView addSubview:tBttFollow];
                }
                
                tShowH+=UserCellH;
                tBttTag++;
            }
        }
 
    
    [_ContentScrollView setContentSize:CGSizeMake(320, tShowH)];
    [self hudWasHidden:nil];
}
                         
- (void)requestFailed:(ASIHTTPRequest *)request
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}

#pragma mark -
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

}
#pragma mark -
#pragma mark MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud{
    p_MBHUD.delegate = nil;
	[p_MBHUD removeFromSuperview];
	[p_MBHUD release];
	p_MBHUD=nil;
}

-(void) addHudLoad{
	if (p_MBHUD == nil) {
		p_MBHUD = [[MBProgressHUD alloc] initWithView:self];
		// Add HUD to screen
		[m_ViewController.navigationController.view addSubview:p_MBHUD];
		// Regisete for HUD callbacks so we can remove it from the window at the right time
		p_MBHUD.delegate = self;
		p_MBHUD.labelText = @"请求数据中...";
		[p_MBHUD show:YES];
	}
}

#pragma mark -
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (m_MainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[m_MainTabBar.viewControllers objectAtIndex:m_MainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return NO;
    }
    if (_DissPingLun == nil) {
        _DissPingLun = [UIButton buttonWithType:UIButtonTypeCustom];
        [_DissPingLun addTarget:self action:@selector(dissPLBtt) forControlEvents:UIControlEventTouchUpInside];
        _DissPingLun.frame =CGRectMake(0, 0, 320, 480);
        [_DissPingLun retain];
    }
    [_DissPingLun removeFromSuperview];
    [self addSubview:_DissPingLun];
    return YES;
}
-(void)dissPLBtt
{
    [_DissPingLun removeFromSuperview];
    [_CommentField resignFirstResponder];
    _CommentField.text =@"";
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    NSLog(@"%d",[_CommentField.text length]);
    if ([_CommentField.text length] <=0) {
        [tAppDel showWithCustomView:@"请输入评论内容" detailText:@"" isCue:NO delayTime:3.0f];
    }else{
        NSString* tPLStr = [NSString stringWithFormat:@"%@?app=blog&act=comment",RequestMainURL];
        [self addHudLoad];
        ASIFormDataRequest* tPLRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:tPLStr]];
        NSLog(@"%@",_CommentField.text);
        NSLog(@"%@",[m_MainTabBar.m_UserDic objectForKey:@"user_id"]);
        
        NSLog(@"%@",[_DettailDataDic objectForKey:@"id"]);
        [tPLRequest setPostValue:[m_MainTabBar.m_UserDic objectForKey:@"user_id"] forKey:@"user_id"];
        [tPLRequest setPostValue:_CommentField.text forKey:@"content"];
        [tPLRequest setPostValue:[_DettailDataDic objectForKey:@"id"] forKey:@"blog_id"];
        [tPLRequest setDelegate:self];
        [tPLRequest setDidFailSelector:@selector(dolikeRequestFail:)];
        [tPLRequest setDidFinishSelector:@selector(commentFinish:)];
        [tPLRequest startAsynchronous];
        [self dissPLBtt];
    }
    
    return YES;
}

-(void) commentFinish:(ASIFormDataRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    [tAppDel showWithCustomView:@"评论成功" detailText:@"" isCue:NO delayTime:3.0f];
    [self hudWasHidden:nil];
    [self requestDetail];
}


-(void) keyboardWillDiss:(NSNotification*)f_Notf
{
    //NSLog(@"%@",[f_Notf description]);
    float tFTime = [[f_Notf.userInfo objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];//
    //CGRect aRect = [[f_Notf.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
   // NSLog(@"%@",[f_Notf description]);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:tFTime];
    _ContentScrollView.frame =CGRectMake(0, 0, 320,480-20-44);
    [UIView commitAnimations];
}
-(void) keyboardWillShow:(NSNotification*)f_Notf
{
    //NSLog(@"%@",[f_Notf description]);
    float tFTime = [[f_Notf.userInfo objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];//
    CGRect aRect = [[f_Notf.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    //NSLog(@"%@",[f_Notf description]);
    
    [self keyFourBttAnima:aRect time:tFTime];
}

-(void) keyFourBttAnima:(CGRect)aRect time:(float)tFTime
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:tFTime];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(showCommentView)];
    _ContentScrollView.frame =CGRectMake(0, 0, 320,480-20-44-aRect.size.height);
    [UIView commitAnimations];
}

-(void)showCommentView
{
    [_ContentScrollView scrollRectToVisible:CGRectMake(0, _ShowFieldH-38, 320, 38) animated:YES];
}

#pragma mark -
#pragma mark 逻辑处理
-(void)topImagePressed:(UIButton*)f_sender
{
    int tTypeImg= [[_DettailDataDic objectForKey:@"image_type"] intValue];
    if (tTypeImg == 3) {
        MPMoviePlayerViewController* tMMPC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[_DettailDataDic objectForKey:@"video"]]];
        [m_ViewController presentMoviePlayerViewControllerAnimated:tMMPC];
        [tMMPC release];
    }
}


-(void)dolikeRequest:(UIButton*)f_sender
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    
    [f_sender setBackgroundImage:[UIImage imageNamed:@"like_button.png"] forState:UIControlStateNormal];//modify by Scott
    [f_sender.titleLabel setTextColor:[UIColor whiteColor]];
    
    NSString* tStrName =f_sender.titleLabel.text;
    NSString* tRequestURL = nil;
    if ([tStrName isEqualToString:@"喜欢"]) {
       tRequestURL =[NSString stringWithFormat:@"%@?app=blog&act=like&user_id=%@&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[_DettailDataDic objectForKey:@"id"]];
    }else if ([tStrName isEqualToString:@"取消喜欢"]) {
        tRequestURL =[NSString stringWithFormat:@"%@?app=blog&act=unlike&user_id=%@&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[_DettailDataDic objectForKey:@"id"]];
    }
    ASIHTTPRequest* tLikeRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:tRequestURL]];
    tLikeRequest.m_Tag =(int)f_sender;
    [tLikeRequest setDelegate:self];
    [tLikeRequest setDidFailSelector:@selector(dolikeRequestFail:)];
    [tLikeRequest setDidFinishSelector:@selector(dolikeRequestFinish:)];
    [tLikeRequest startAsynchronous];
    //[self addHudLoad];//modify by Scott
}

-(void)dolikeRequestFail:(ASIHTTPRequest*)request
{
    [self hudWasHidden:nil];
    
    UIButton* tSendBtt = (UIButton*)request.m_Tag;
    [tSendBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];//modify by Scott
    [tSendBtt.titleLabel setTextColor:[UIColor blackColor]];
    
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
-(void)dolikeRequestFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    UIButton* tSendBtt = (UIButton*)request.m_Tag;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [tSendBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];//modify by Scott
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        //[self requestDetail];//modify by Scott
        [tSendBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];//modify by Scott
        
        return;
    }
    
    if ([request.url.absoluteString rangeOfString:@"unlike"].location != NSNotFound) {
        [tSendBtt setTitle:@"喜欢" forState:UIControlStateNormal];
    }else{
        [tSendBtt setTitle:@"取消喜欢" forState:UIControlStateNormal];
    }
    [tSendBtt setBackgroundImage:[UIImage imageNamed:@"forward_button.png"] forState:UIControlStateNormal];//modify by Scott
    [tSendBtt.titleLabel setTextColor:[UIColor blackColor]];
    [self hudWasHidden:nil];
    //[self requestDetail];//modify by Scott
}
//看专辑里的
-(void) bttToShowPBL:(UIButton*)f_sender
{
    NSArray* tForwardsArr =[_DettailDataDic objectForKey:@"forwards"];
    NSDictionary* tDic = [tForwardsArr objectAtIndex:f_sender.tag];
    MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    CollectListViewController* tNextVC = [[CollectListViewController alloc] init];
    tNextVC.navigationItem.hidesBackButton =YES;
    tNextVC.m_NowModeType=Mode_Type_CollectList;
    tNextVC.m_UserID =[tDic objectForKey:@"user_id"];
    //    tNextVC.m_ShowUserID = [NSString stringWithFormat:@"%d",tAlbDic.userid];
    tNextVC.m_Collect_ID = [tDic objectForKey:@"id"];
    //tNextVC.type = m_type;
    [m_ViewController.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}
//转采
-(void)ZCBttPressed
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    
    AddAlbumViewController* tShowAdd =[[AddAlbumViewController alloc] initType:FORWARD_BLOG];
    id tObjectView =[_ContentScrollView viewWithTag:0x300];
    UIImage* tImg = nil;
    if ([tObjectView isKindOfClass:[AsyncImageView class]]) {
        tImg = [((AsyncImageView*)tObjectView) GetUIImage];
    }else if([tObjectView isKindOfClass:[SCGIFImageView class]]){
        tImg = [((SCGIFImageView*)tObjectView) getFrameAsImageAtIndex:0];
    }
    tShowAdd.headimage =tImg;
    NSLog(@"%@",[_DettailDataDic objectForKey:@"user_id"]);
    tShowAdd.user_id = [tMainTabBar.m_UserDic objectForKey:@"user_id"];//modify by Scott
    tShowAdd.titletext= [_DettailDataDic objectForKey:@"description"];
//    tShowAdd.Albumname= [_DettailDataDic objectForKey:@"collect_name"];
    tShowAdd.blogid= [_DettailDataDic objectForKey:@"id"];
    tShowAdd.navigationItem.hidesBackButton =YES;
    tMainTabBar.m_TabbarCustom.hidden = YES;
    [m_ViewController.navigationController pushViewController:tShowAdd animated:YES];
    [tShowAdd release];
    
//    ASIHTTPRequest* tUserRequest =[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?app=userNew&act=detail&user_id=%@&id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[tMainTabBar.m_UserDic objectForKey:@"user_id"]]]];
//    [tUserRequest setDelegate:self];
//    [tUserRequest setDidFailSelector:@selector(getSelfUserFail:)];
//    [tUserRequest setDidFinishSelector:@selector(getSelfUserFinish:)];
//    [tUserRequest startAsynchronous];
//    [self addHudLoad];
}


-(void) guanZhuBtt:(UIButton*)f_sender
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        m_NeedFirstDataRequest=YES;
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    NSArray* tLikesArr =[_DettailDataDic objectForKey:@"likes"];
    NSDictionary* tSeeObject = [tLikesArr objectAtIndex:f_sender.tag];
    
    if ([f_sender.titleLabel.text isEqualToString:@"关注"]) {
        NSString* url = [NSString stringWithFormat:@"%@?app=userNew&act=follow&type=1&user_id=%@&target_user_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[tSeeObject objectForKey:@"user_id"]];
        NSLog(@"urlFans = %@",url);
        ASIHTTPRequest* tGetRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
        //    [tGetRequest setTimeOutSeconds:20.f];
        tGetRequest.m_Tag = (int)f_sender;
        [tGetRequest setDelegate:self];
        [tGetRequest setDidFailSelector:@selector(dolikeRequestFail:)];
        [tGetRequest setDidFinishSelector:@selector(guanZhuFinish:)];
        [tGetRequest startAsynchronous];
    }else{
        NSString* url = [NSString stringWithFormat:@"%@?app=userNew&act=follow&type=2&user_id=%@&target_user_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[tSeeObject objectForKey:@"user_id"]];
        NSLog(@"urlFans = %@",url);
        ASIHTTPRequest* tGetRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
        //    [tGetRequest setTimeOutSeconds:20.f];
        tGetRequest.m_Tag = (int)f_sender;
        [tGetRequest setDelegate:self];
        [tGetRequest setDidFailSelector:@selector(dolikeRequestFail:)];
        [tGetRequest setDidFinishSelector:@selector(cancelguanZhuFinish:)];
        [tGetRequest startAsynchronous];
    }
}

-(void) guanZhuFinish:(ASIFormDataRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    UIButton* tGZBtt = (UIButton*)request.m_Tag;
    [tGZBtt setTitle:@"取消关注" forState:UIControlStateNormal];
    [tAppDel showWithCustomView:@"关注成功" detailText:@"" isCue:NO delayTime:2.0f];
    [self hudWasHidden:nil];
}

-(void) cancelguanZhuFinish:(ASIFormDataRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    UIButton* tGZBtt = (UIButton*)request.m_Tag;
    [tGZBtt setTitle:@"关注" forState:UIControlStateNormal];
    [tAppDel showWithCustomView:@"取消关注成功" detailText:@"" isCue:NO delayTime:2.0f];
    [self hudWasHidden:nil];
}


-(void) shareWeiBo
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    if (_SharePick == nil) {
        _SharePick = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"分享到新浪微博",@"分享到腾讯微博",@"保存到相薄", nil];
        _SharePick.delegate =self;
       
    }
     [_SharePick showFromTabBar:m_ViewController.navigationController.tabBarController.tabBar];
}

#pragma mark-
#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSURL* tRequestURL =nil;
    if (buttonIndex == 2) {
        id tObjectView =[_ContentScrollView viewWithTag:0x300];
        UIImage* tImg = nil;
        if ([tObjectView isKindOfClass:[AsyncImageView class]]) {
            tImg = [((AsyncImageView*)tObjectView) GetUIImage];
        }else if([tObjectView isKindOfClass:[SCGIFImageView class]]){
            tImg = [((SCGIFImageView*)tObjectView) getFrameAsImageAtIndex:0];
        }
        UIImageWriteToSavedPhotosAlbum(tImg, nil, nil, nil);
        AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [tAppDel showWithCustomView:@"已经保存到相薄" detailText:@"" isCue:NO delayTime:2.0f];

    }else if(buttonIndex ==0){
        MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
        
        tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@?app=blog&act=share&user_id=%@&target=sina&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[_DettailDataDic objectForKey:@"id"]]];
    }else if(buttonIndex == 1){
        MainTabBarController* tMainTabBar =(MainTabBarController*)m_ViewController.navigationController.tabBarController;
        tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@?app=blog&act=share&user_id=%@&target=tencent&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[_DettailDataDic objectForKey:@"id"]]];
    }
    if (tRequestURL != nil) {
        [self addHudLoad];
        ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
        [tRequestSearchNum setDelegate:self];
        [tRequestSearchNum setDidFailSelector:@selector(requestShareFail:)];
        [tRequestSearchNum setDidFinishSelector:@selector(requestShareFinish:)];
        [tRequestSearchNum startAsynchronous];
    }
}

-(void) requestShareFail:(ASIHTTPRequest*)request
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
-(void) requestShareFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        if (tErrorCode == 1005) {
            MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
            SettingViewController* ichoosealbum = [[SettingViewController alloc] init];
            ichoosealbum.name = [tMainTabBar.m_UserDic objectForKey:@"nickname"];
            ichoosealbum.headurl = [tMainTabBar.m_UserDic objectForKey:@"avatar"];
            ichoosealbum.navigationItem.hidesBackButton = YES;
            tMainTabBar.m_TabbarCustom.hidden = YES;
            [m_ViewController.navigationController pushViewController:ichoosealbum animated:YES];
            [ichoosealbum release];
        }
        return;
    }
    [tAppDel showWithCustomView:@"分享成功" detailText:@"" isCue:NO delayTime:2.0f];
    [self hudWasHidden:nil];
}



-(void) pressedShowCollect
{
    if ([_DettailDataDic objectForKey:@"collect_id"] != nil) {
        MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
        tMainTabBar.m_TabbarCustom.hidden =YES;
        CollectListViewController* tNextVC = [[CollectListViewController alloc] init];
        tNextVC.navigationItem.hidesBackButton =YES;
        tNextVC.m_NowModeType=Mode_Type_CollectList;
        tNextVC.m_UserID =
        [NSString stringWithFormat:@"%d",[[_DettailDataDic objectForKey:@"user_id"] intValue]];
        //    tNextVC.m_ShowUserID = [NSString stringWithFormat:@"%d",tAlbDic.userid];
        tNextVC.m_Collect_ID = [NSString stringWithFormat:@"%d",[[_DettailDataDic objectForKey:@"collect_id"] intValue]];
        //tNextVC.type = m_type;
        [m_ViewController.navigationController pushViewController:tNextVC animated:YES];
        [tNextVC release];
    }
}

-(void) pressedHeader
{

    MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:[_DettailDataDic objectForKey:@"user_id"]];
    tNextVC.navigationItem.hidesBackButton =YES;
    [m_ViewController.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}
-(void)pressedLikeHead:(UIButton*)f_sender
{
    NSArray* tLikesArr =[_DettailDataDic objectForKey:@"likes"];
    NSDictionary* tDic = [tLikesArr objectAtIndex:f_sender.tag];
    
    
    MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:[tDic objectForKey:@"user_id"]];
    tNextVC.navigationItem.hidesBackButton =YES;
    [m_ViewController.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}

-(void)pressedCommHead:(UIButton*)f_sender
{
    NSArray* tCommArr =[_DettailDataDic objectForKey:@"comments"];
    NSDictionary* tDic = [tCommArr objectAtIndex:f_sender.tag];
    
    
    MainTabBarController* tMainTabBar = (MainTabBarController*)m_ViewController.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:[tDic objectForKey:@"user_id"]];
    tNextVC.navigationItem.hidesBackButton =YES;
    [m_ViewController.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}

//-(void)getSelfUserFail:(ASIHTTPRequest*)request
//{
//    [self hudWasHidden:nil];
//    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
//    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
//}
//-(void)getSelfUserFinish:(ASIHTTPRequest*)request
//{
//    NSError* tError;
//    NSString* tReqStr =[request responseString];
//    NSLog(@"ads json data =%@",[request responseString]);
//    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
//    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
//    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
//    if (tDictionary == nil) {
//        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
//        [self hudWasHidden:nil];
//        return;
//    }
//    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
//    if (tErrorCode != 0) {
//        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
//        [self hudWasHidden:nil];
//        return;
//    }
//    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
//    NSDictionary* tDataDic =[tDictionary objectForKey:@"data"];
//    ASIHTTPRequest* tHeaderImgRequest =[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[tDataDic objectForKey:@"avatar"]]];
//    [tHeaderImgRequest startSynchronous];
//    SettingViewController* setting = [[SettingViewController alloc] init];
//    setting.headimage =[UIImage imageWithData:[tHeaderImgRequest responseData]];
//    setting.name = [tDataDic objectForKey:@"nickname"];
//    setting.navigationItem.hidesBackButton =YES;
//    tMainTabBar.m_TabbarCustom.hidden = YES;
//    [self.navigationController pushViewController:setting animated:YES];
//    [setting release];
//    
//    [self hudWasHidden:nil];
//}
@end
